package com.work.ygj.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.work.ygj.common.model.Response;
import com.work.ygj.common.model.page.PageResult;
import com.work.ygj.entity.UserComplaint;
import com.work.ygj.pojo.dto.UserComplaintDto;
import com.work.ygj.pojo.vo.UserComplaintVo;
import com.work.ygj.service.UserComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  用户投诉管理(管理员)
 *
 * @author ygj
 * @since 2022-03-27
 */
@Controller
@RequestMapping("/userComplaint")
@ResponseBody
public class UserComplaintController extends BaseController {

    @Autowired
    private UserComplaintService userComplaintService;

    /**
     * 用户投诉列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public Response<PageResult<UserComplaintVo>> selectList(@RequestBody UserComplaintDto dto){
        return Response.success(getDataTable(userComplaintService.selectList(dto)));
    }

    /**
     * 新增用户投诉信息
     *
     * @param req
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody UserComplaint req) {
        userComplaintService.save(req);
        return Response.success();
    }


    /**
     * 修改用户投诉信息
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Response update(@RequestBody UserComplaint req) {
        UpdateWrapper<UserComplaint> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", req.getId());
        userComplaintService.update(req, updateWrapper);
        return Response.success();
    }

    /**
     * 删除用户投诉记录
     *
     * @param req
     * @return
     */
    @PostMapping("/del")
    public Response del(@RequestBody UserComplaint req) {
        UserComplaint entity = new UserComplaint();
        entity.setId(req.getId());
        entity.setDeleted("1");
        userComplaintService.updateById(entity);
        return Response.success();
    }

    /**
     * 访客用户投诉详情
     *
     * @param req
     * @return
     */
    @PostMapping("/detail")
    public Response<UserComplaint> detail(@RequestBody UserComplaint req) {
        UserComplaint entity = userComplaintService.getById(req.getId());
        return Response.success(entity);
    }
}

